<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use DB;

class collectionController extends Controller
{
    // 展示收藏商品信息
    public function index(){    	
    	$list = DB::table('collect')
    		->join('order', 'collect.oid', '=', 'order.id')
    		->join('detail', 'order.pid', '=', 'detail.id')
	    	->select('order.*', 'detail.title', 'detail.pic', 'detail.price')
	    	->get()
	    	->all();	    
    	return view('home.person.collection', ['list' => $list]);
    }

    // 添加收藏商品信息
    public function collect($id){
    	$oid = DB::table('collect')->insertGetId(['oid' => $id, 'stime' => time()]);
    	if($oid > 1){
    		echo "<script>alert('恭喜，收藏成功！');window.history.back(-1)</script>";
    	}
    }

    // 取消收藏，并删除数据库收藏表里对应的数据
    public function unCollection($oid){    	
    	$row = DB::table('collect')->where('oid', $oid)->delete();
    	return back();
    }
}
